from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, JSON
from sqlalchemy.sql import func
from app.database import Base

class SystemSetting(Base):
    __tablename__ = "system_settings"

    id = Column(Integer, primary_key=True, index=True)
    category = Column(String(50), nullable=False)  # system, security, notification
    key = Column(String(100), nullable=False, unique=True)  # 设置键名
    value = Column(Text)  # 设置值（字符串格式）
    data_type = Column(String(20), default="string")  # string, integer, boolean, json
    description = Column(Text)  # 设置描述
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())

class UserSetting(Base):
    __tablename__ = "user_settings"

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, nullable=False, index=True)
    category = Column(String(50), nullable=False)  # preferences, notification
    settings = Column(JSON)  # 用户设置JSON数据
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())